package middleware

import (
	"fmt"
	"net/http"
)

type UserIdHeaderMixMiddleware struct {
}

const (
	userKey = `x-user-id`
)

func NewUserIdHeaderMixMiddleware() *UserIdHeaderMixMiddleware {
	return &UserIdHeaderMixMiddleware{}
}

func (m *UserIdHeaderMixMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		jwtUserId := r.Context().Value("userId")
		r.Header.Set(userKey, fmt.Sprintf("%v", jwtUserId))
		next(w, r)
	}
}
